home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / LSLAST.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  96 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lslast.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10.  
  11. /* local headers */
  12. #include "lseq_.h"
  13.  
  14. /*man---------------------------------------------------------------------------
  15. NAME
  16.      lslast - last lseq record
  17.  
  18. SYNOPSIS
  19.      #include <lseq.h>
  20.  
  21.      int lslast(lsp)
  22.      lseq_t *lsp;
  23.  
  24. DESCRIPTION
  25.      The lslast function positions the cursor of lseq lsp on the last
  26.      record in that lseq.
  27.  
  28.      lslast will fail if one or more of the following is true:
  29.  
  30.      [EINVAL]       lsp is not a valid lseq pointer.
  31.      [LSELOCK]      lsp is not locked.
  32.      [LSENOPEN]     lsp is not open.
  33.      [LSENREC]      lsp is empty.
  34.  
  35. SEE ALSO
  36.      lsfirst, lsnext, lsprev, lsreccnt.
  37.  
  38. DIAGNOSTICS
  39.      Upon successful completion, a value of 0 is returned.  Otherwise,
  40.      a value of -1 is returned, and errno set to indicate the error.
  41.  
  42. ------------------------------------------------------------------------------*/
  43. #ifdef AC_PROTO
  44. int lslast(lseq_t *lsp)
  45. #else
  46. int lslast(lsp)
  47. lseq_t *lsp;
  48. #endif
  49. {
  50.     /* validate arguments */
  51.     if (!ls_valid(lsp)) {
  52.         errno = EINVAL;
  53.         return -1;
  54.     }
  55.  
  56.     /* check if not open */
  57.     if (!(lsp->flags & LSOPEN)) {
  58.         errno = LSENOPEN;
  59.         return -1;
  60.     }
  61.  
  62.     /* check locks */
  63.     if (!(lsp->flags & LSLOCKS)) {
  64.         errno = LSELOCK;
  65.         return -1;
  66.     }
  67.  
  68.     /* check if lsp is empty */
  69.     if (lsp->lshdr.reccnt == NIL) {
  70.         errno = LSENREC;
  71.         return -1;
  72.     }
  73.  
  74.     /* check if already on last record */
  75.     if (lsp->clspos == lsp->lshdr.last) {
  76.         return 0;
  77.     }
  78.  
  79.     /* set cursor to last record */
  80.     lsp->clspos = lsp->lshdr.last;
  81.  
  82.     /* read in last record */
  83.     if (lsp->clspos == NIL) {
  84.         LSEPRINT;
  85.         errno = LSEPANIC;
  86.         return -1;
  87.     } else {
  88.         if (ls_rcget(lsp, lsp->clspos, lsp->clsrp) == -1) {
  89.             LSEPRINT;
  90.             return -1;
  91.         }
  92.     }
  93.  
  94.     return 0;
  95. }
  96.